package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.kuser;
import com.ruoyi.system.service.IkuserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师信息Controller
 *
 * @author 金先生
 * @date 2022-03-21
 */
@Controller
@RequestMapping("/system/kuser")
public class kuserController extends BaseController
{
    private String prefix = "system/kuser";

    @Autowired
    private IkuserService kuserService;

    @RequiresPermissions("system:kuser:view")
    @GetMapping()
    public String kuser()
    {
        return prefix + "/kuser";
    }

    /**
     * 查询教师信息列表
     */
    @RequiresPermissions("system:kuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(kuser kuser)
    {
        startPage();
        List<kuser> list = kuserService.selectkuserList(kuser);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @RequiresPermissions("system:kuser:export")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(kuser kuser)
    {
        List<kuser> list = kuserService.selectkuserList(kuser);
        ExcelUtil<kuser> util = new ExcelUtil<kuser>(kuser.class);
        return util.exportExcel(list, "教师信息数据");
    }

    /**
     * 新增教师信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教师信息
     */
    @RequiresPermissions("system:kuser:add")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(kuser kuser)
    {
        return toAjax(kuserService.insertkuser(kuser));
    }

    /**
     * 修改教师信息
     */
    @RequiresPermissions("system:kuser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        kuser kuser = kuserService.selectkuserById(id);
        mmap.put("kuser", kuser);
        return prefix + "/edit";
    }

    /**
     * 修改保存教师信息
     */
    @RequiresPermissions("system:kuser:edit")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(kuser kuser)
    {
        return toAjax(kuserService.updatekuser(kuser));
    }

    /**
     * 删除教师信息
     */
    @RequiresPermissions("system:kuser:remove")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kuserService.deletekuserByIds(ids));
    }


    /**
     * 删除单条日志
     */
    @RequiresPermissions("system:kuser:remove")
    @Log(title = "日志", businessType = BusinessType.DELETE)
    @GetMapping( "/removeById/{logId}")
    @ResponseBody
    public AjaxResult removeById(@PathVariable("logId") Long logId)
    {
        int rows = kuserService.deletekuserById(logId);
        System.out.println("SchoolDaylongController.removeById"+logId);
        return toAjax(rows);
    }
}
